using System.Collections;
using UnityEngine;

namespace VoxelEngine
{
	public class BlockTypes : MonoBehaviour
	{
		public static BlockTypes Instance;

		private BlockBase _dirtType;

		private BlockBase _grassType;

		private BlockBase _stoneType;

		private BlockBase _lavaType;

		private BlockBase _woodPlankType;

		private BlockBase _brickType;

		private BlockBase _woodType;

		private BlockBase _foliageType;

		private BlockBase _lightGreenFoliage;

		private BlockBase _blueFoliage;

		private BlockBase _redFoliage;

		private BlockBase _hardStone;

		private BlockBase _grayBrick;

		private BlockBase _sand;

		private BlockBase _darkWoodPlank;

		private BlockBase _glass;

		private BlockBase _bush;

		private BlockBase _halfTopBrick;

		private BlockBase _halfBottomBrick;

		private BlockBase _halfTopGrayBrick;

		private BlockBase _halfBottomGrayBrick;

		private BlockBase _mixedBrickAndGrayBrick;

		private BlockBase _mixedGrayBrickAndBrick;

		private BlockBase _redType;

		private BlockBase _orangeType;

		private BlockBase _yellowType;

		private BlockBase _greenType;

		private BlockBase _blueType;

		private BlockBase _purpleType;

		private BlockBase _pinkType;

		private BlockBase _whiteType;

		private BlockBase _grayType;

		private BlockBase _blackType;

		private BlockBase _lightType;

		private BlockBase _waterType;

		private BlockBase _airType;

		private BlockBase _heightType;

		private BlockBase _worldBoundType;

		private BlockBase _unknownType;

		private BlockBase _numberOne;

		private BlockBase _numberTwo;

		private BlockBase _numberThree;

		private BlockBase _numberFour;

		private BlockBase _numberFive;

		private BlockBase _numberSix;

		private BlockBase _numberSeven;

		private BlockBase _numberEight;

		private BlockBase _numberNine;

		private BlockBase _numberTen;

		private BlockBase _numberEleven;

		private BlockBase _numberTwelve;

		private BlockBase _numberThirteen;

		private BlockBase _numberFourteen;

		private BlockBase _numberFifteen;

		private BlockBase _numberSixteen;

		private BlockBase _colorOne;

		private BlockBase _colorTwo;

		private BlockBase _colorThree;

		private BlockBase _colorFour;

		private BlockBase _colorFive;

		private BlockBase _colorSix;

		private BlockBase _colorSeven;

		private BlockBase _colorEight;

		private BlockBase _colorNine;

		private BlockBase _colorTen;

		private BlockBase _colorEleven;

		private BlockBase _colorTwelve;

		private BlockBase _colorThirteen;

		private BlockBase _colorFourteen;

		private BlockBase _colorFifteen;

		private BlockBase _colorSixteen;

		protected void Awake()
		{
			Instance = this;
			ResolveBlockBaseList();
		}

		public IEnumerator Start()
		{
			yield return null;
		}

		private void ResolveBlockBaseList()
		{
			BlockBaseList blockBaseList = BaseWorldController.VoxelPlayerData.VoxelWorldData.BlockBaseList;
			if (blockBaseList == null)
			{
				UnityEngine.Debug.LogError("[BlockTypes] blockBaseList unavailable");
			}
			else
			{
				CreateBlockBaseList(blockBaseList);
			}
		}

		protected void OnDestroy()
		{
			Instance = null;
		}

		private void CreateBlockBaseList(BlockBaseList list)
		{
			foreach (BlockBaseList.BlockBaseListItem item in list.List)
			{
				switch (item.Type)
				{
				case BlockType.Dirt:
					_dirtType = item.BlockBase;
					break;
				case BlockType.Grass:
					_grassType = item.BlockBase;
					break;
				case BlockType.Stone:
					_stoneType = item.BlockBase;
					break;
				case BlockType.Lava:
					_lavaType = item.BlockBase;
					break;
				case BlockType.WoodPlank:
					_woodPlankType = item.BlockBase;
					break;
				case BlockType.Brick:
					_brickType = item.BlockBase;
					break;
				case BlockType.Wood:
					_woodType = item.BlockBase;
					break;
				case BlockType.Foliage:
					_foliageType = item.BlockBase;
					break;
				case BlockType.LightGreenFoliage:
					_lightGreenFoliage = item.BlockBase;
					break;
				case BlockType.BlueFoliage:
					_blueFoliage = item.BlockBase;
					break;
				case BlockType.RedFoliage:
					_redFoliage = item.BlockBase;
					break;
				case BlockType.HardStone:
					_hardStone = item.BlockBase;
					break;
				case BlockType.GrayBrick:
					_grayBrick = item.BlockBase;
					break;
				case BlockType.Sand:
					_sand = item.BlockBase;
					break;
				case BlockType.DarkWoodPlank:
					_darkWoodPlank = item.BlockBase;
					break;
				case BlockType.Glass:
					_glass = item.BlockBase;
					break;
				case BlockType.Bush:
					_bush = item.BlockBase;
					break;
				case BlockType.HalfTopBrick:
					_halfTopBrick = item.BlockBase;
					break;
				case BlockType.HalfBottomBrick:
					_halfBottomBrick = item.BlockBase;
					break;
				case BlockType.HalfTopGrayBrick:
					_halfTopGrayBrick = item.BlockBase;
					break;
				case BlockType.HalfBottomGrayBrick:
					_halfBottomGrayBrick = item.BlockBase;
					break;
				case BlockType.MixedBrickAndGrayBrick:
					_mixedBrickAndGrayBrick = item.BlockBase;
					break;
				case BlockType.MixedGrayBrickAndBrick:
					_mixedGrayBrickAndBrick = item.BlockBase;
					break;
				case BlockType.Red:
					_redType = item.BlockBase;
					break;
				case BlockType.Orange:
					_orangeType = item.BlockBase;
					break;
				case BlockType.Yellow:
					_yellowType = item.BlockBase;
					break;
				case BlockType.Green:
					_greenType = item.BlockBase;
					break;
				case BlockType.Blue:
					_blueType = item.BlockBase;
					break;
				case BlockType.Purple:
					_purpleType = item.BlockBase;
					break;
				case BlockType.Pink:
					_pinkType = item.BlockBase;
					break;
				case BlockType.White:
					_whiteType = item.BlockBase;
					break;
				case BlockType.Gray:
					_grayType = item.BlockBase;
					break;
				case BlockType.Black:
					_blackType = item.BlockBase;
					break;
				case BlockType.One:
					_numberOne = item.BlockBase;
					break;
				case BlockType.Two:
					_numberTwo = item.BlockBase;
					break;
				case BlockType.Three:
					_numberThree = item.BlockBase;
					break;
				case BlockType.Four:
					_numberFour = item.BlockBase;
					break;
				case BlockType.Five:
					_numberFive = item.BlockBase;
					break;
				case BlockType.Six:
					_numberSix = item.BlockBase;
					break;
				case BlockType.Seven:
					_numberSeven = item.BlockBase;
					break;
				case BlockType.Eight:
					_numberEight = item.BlockBase;
					break;
				case BlockType.Nine:
					_numberNine = item.BlockBase;
					break;
				case BlockType.Ten:
					_numberTen = item.BlockBase;
					break;
				case BlockType.Eleven:
					_numberEleven = item.BlockBase;
					break;
				case BlockType.Twelve:
					_numberTwelve = item.BlockBase;
					break;
				case BlockType.Thirteen:
					_numberThirteen = item.BlockBase;
					break;
				case BlockType.Fourteen:
					_numberFourteen = item.BlockBase;
					break;
				case BlockType.Fifteen:
					_numberFifteen = item.BlockBase;
					break;
				case BlockType.Sixteen:
					_numberSixteen = item.BlockBase;
					break;
				case BlockType.ColorOne:
					_colorOne = item.BlockBase;
					break;
				case BlockType.ColorTwo:
					_colorTwo = item.BlockBase;
					break;
				case BlockType.ColorThree:
					_colorThree = item.BlockBase;
					break;
				case BlockType.ColorFour:
					_colorFour = item.BlockBase;
					break;
				case BlockType.ColorFive:
					_colorFive = item.BlockBase;
					break;
				case BlockType.ColorSix:
					_colorSix = item.BlockBase;
					break;
				case BlockType.ColorSeven:
					_colorSeven = item.BlockBase;
					break;
				case BlockType.ColorEight:
					_colorEight = item.BlockBase;
					break;
				case BlockType.ColorNine:
					_colorNine = item.BlockBase;
					break;
				case BlockType.ColorTen:
					_colorTen = item.BlockBase;
					break;
				case BlockType.ColorEleven:
					_colorEleven = item.BlockBase;
					break;
				case BlockType.ColorTwelve:
					_colorTwelve = item.BlockBase;
					break;
				case BlockType.ColorThirteen:
					_colorThirteen = item.BlockBase;
					break;
				case BlockType.ColorFourteen:
					_colorFourteen = item.BlockBase;
					break;
				case BlockType.ColorFifteen:
					_colorFifteen = item.BlockBase;
					break;
				case BlockType.ColorSixteen:
					_colorSixteen = item.BlockBase;
					break;
				case BlockType.Light:
					_lightType = item.BlockBase;
					break;
				case BlockType.Water:
					_waterType = item.BlockBase;
					break;
				case BlockType.Air:
					_airType = item.BlockBase;
					break;
				case BlockType.Height:
					_heightType = item.BlockBase;
					break;
				case BlockType.WorldBound:
					_worldBoundType = item.BlockBase;
					break;
				default:
					_unknownType = item.BlockBase;
					break;
				}
			}
		}

		public BlockBase GetBlockType(byte type)
		{
			switch (type)
			{
			case 0:
				return _dirtType;
			case 1:
				return _grassType;
			case 2:
				return _stoneType;
			case 3:
				return _lavaType;
			case 4:
				return _woodType;
			case 5:
				return _woodPlankType;
			case 6:
				return _brickType;
			case 7:
				return _foliageType;
			case 8:
				return _lightGreenFoliage;
			case 9:
				return _blueFoliage;
			case 10:
				return _redFoliage;
			case 11:
				return _hardStone;
			case 12:
				return _grayBrick;
			case 13:
				return _sand;
			case 14:
				return _darkWoodPlank;
			case 15:
				return _glass;
			case 16:
				return _bush;
			case 80:
				return _halfTopBrick;
			case 81:
				return _halfBottomBrick;
			case 82:
				return _halfTopGrayBrick;
			case 83:
				return _halfBottomGrayBrick;
			case 84:
				return _mixedBrickAndGrayBrick;
			case 85:
				return _mixedGrayBrickAndBrick;
			case 100:
				return _redType;
			case 101:
				return _orangeType;
			case 102:
				return _yellowType;
			case 103:
				return _greenType;
			case 104:
				return _blueType;
			case 105:
				return _purpleType;
			case 106:
				return _pinkType;
			case 107:
				return _whiteType;
			case 108:
				return _blackType;
			case 109:
				return _grayType;
			case 250:
				return _waterType;
			case 251:
				return _lightType;
			case 252:
				return _airType;
			case 253:
				return _heightType;
			case 254:
				return _worldBoundType;
			default:
				return GetNumberBlock((BlockType)type);
			}
		}

		public BlockBase GetBlockType(BlockType type)
		{
			switch (type)
			{
			case BlockType.Dirt:
				return _dirtType;
			case BlockType.Grass:
				return _grassType;
			case BlockType.Stone:
				return _stoneType;
			case BlockType.Lava:
				return _lavaType;
			case BlockType.WoodPlank:
				return _woodPlankType;
			case BlockType.Brick:
				return _brickType;
			case BlockType.Wood:
				return _woodType;
			case BlockType.Foliage:
				return _foliageType;
			case BlockType.LightGreenFoliage:
				return _lightGreenFoliage;
			case BlockType.BlueFoliage:
				return _blueFoliage;
			case BlockType.RedFoliage:
				return _redFoliage;
			case BlockType.HardStone:
				return _hardStone;
			case BlockType.GrayBrick:
				return _grayBrick;
			case BlockType.Sand:
				return _sand;
			case BlockType.DarkWoodPlank:
				return _darkWoodPlank;
			case BlockType.Glass:
				return _glass;
			case BlockType.Bush:
				return _bush;
			case BlockType.HalfTopBrick:
				return _halfTopBrick;
			case BlockType.HalfBottomBrick:
				return _halfBottomBrick;
			case BlockType.HalfTopGrayBrick:
				return _halfTopGrayBrick;
			case BlockType.HalfBottomGrayBrick:
				return _halfBottomGrayBrick;
			case BlockType.MixedBrickAndGrayBrick:
				return _mixedBrickAndGrayBrick;
			case BlockType.MixedGrayBrickAndBrick:
				return _mixedGrayBrickAndBrick;
			case BlockType.Red:
				return _redType;
			case BlockType.Orange:
				return _orangeType;
			case BlockType.Yellow:
				return _yellowType;
			case BlockType.Green:
				return _greenType;
			case BlockType.Blue:
				return _blueType;
			case BlockType.Purple:
				return _purpleType;
			case BlockType.Pink:
				return _pinkType;
			case BlockType.White:
				return _whiteType;
			case BlockType.Gray:
				return _grayType;
			case BlockType.Black:
				return _blackType;
			case BlockType.Light:
				return _lightType;
			case BlockType.Water:
				return _waterType;
			case BlockType.Air:
				return _airType;
			case BlockType.Height:
				return _heightType;
			case BlockType.WorldBound:
				return _worldBoundType;
			default:
				return GetNumberBlock(type);
			}
		}

		private BlockBase GetNumberBlock(BlockType number)
		{
			switch (number)
			{
			case BlockType.One:
				return _numberOne;
			case BlockType.Two:
				return _numberTwo;
			case BlockType.Three:
				return _numberThree;
			case BlockType.Four:
				return _numberFour;
			case BlockType.Five:
				return _numberFive;
			case BlockType.Six:
				return _numberSix;
			case BlockType.Seven:
				return _numberSeven;
			case BlockType.Eight:
				return _numberEight;
			case BlockType.Nine:
				return _numberNine;
			case BlockType.Ten:
				return _numberTen;
			case BlockType.Eleven:
				return _numberEleven;
			case BlockType.Twelve:
				return _numberTwelve;
			case BlockType.Thirteen:
				return _numberThirteen;
			case BlockType.Fourteen:
				return _numberFourteen;
			case BlockType.Fifteen:
				return _numberFifteen;
			case BlockType.Sixteen:
				return _numberSixteen;
			case BlockType.ColorOne:
				return _colorOne;
			case BlockType.ColorTwo:
				return _colorTwo;
			case BlockType.ColorThree:
				return _colorThree;
			case BlockType.ColorFour:
				return _colorFour;
			case BlockType.ColorFive:
				return _colorFive;
			case BlockType.ColorSix:
				return _colorSix;
			case BlockType.ColorSeven:
				return _colorSeven;
			case BlockType.ColorEight:
				return _colorEight;
			case BlockType.ColorNine:
				return _colorNine;
			case BlockType.ColorTen:
				return _colorTen;
			case BlockType.ColorEleven:
				return _colorEleven;
			case BlockType.ColorTwelve:
				return _colorTwelve;
			case BlockType.ColorThirteen:
				return _colorThirteen;
			case BlockType.ColorFourteen:
				return _colorFourteen;
			case BlockType.ColorFifteen:
				return _colorFifteen;
			case BlockType.ColorSixteen:
				return _colorSixteen;
			default:
				return _unknownType;
			}
		}

		public static bool IsHalfBlock(BlockType type)
		{
			switch (type)
			{
			case BlockType.HalfTopBrick:
			case BlockType.HalfBottomBrick:
			case BlockType.HalfTopGrayBrick:
			case BlockType.HalfBottomGrayBrick:
				return true;
			default:
				return false;
			}
		}

		public BlockType GetHalfCounterPart(BlockType halfType)
		{
			switch (halfType)
			{
			case BlockType.HalfTopBrick:
				return BlockType.HalfBottomBrick;
			case BlockType.HalfBottomBrick:
				return BlockType.HalfTopBrick;
			case BlockType.HalfTopGrayBrick:
				return BlockType.HalfBottomGrayBrick;
			case BlockType.HalfBottomGrayBrick:
				return BlockType.HalfTopGrayBrick;
			default:
				return BlockType.Unknown;
			}
		}

		public BlockType GetHalfPartByVolume(BlockType halfType, BlockVolume volume)
		{
			switch (halfType)
			{
			case BlockType.HalfTopBrick:
			case BlockType.HalfBottomBrick:
				switch (volume)
				{
				case BlockVolume.HalfTop:
					return BlockType.HalfTopBrick;
				case BlockVolume.HalfBottom:
					return BlockType.HalfBottomBrick;
				}
				break;
			case BlockType.HalfTopGrayBrick:
			case BlockType.HalfBottomGrayBrick:
				switch (volume)
				{
				case BlockVolume.HalfTop:
					return BlockType.HalfTopGrayBrick;
				case BlockVolume.HalfBottom:
					return BlockType.HalfBottomGrayBrick;
				}
				break;
			}
			return BlockType.Unknown;
		}

		public bool IsBottomPart(BlockType type)
		{
			return type == BlockType.HalfBottomBrick || type == BlockType.HalfBottomGrayBrick;
		}

		public bool IsTopPart(BlockType type)
		{
			return type == BlockType.HalfTopBrick || type == BlockType.HalfTopGrayBrick;
		}

		public BlockType GetMixedBlock(BlockType halfType1, BlockType halfType2)
		{
			BlockType blockType = (!IsBottomPart(halfType1)) ? halfType2 : halfType1;
			BlockType blockType2 = (!IsTopPart(halfType2)) ? halfType1 : halfType2;
			switch (blockType)
			{
			case BlockType.HalfBottomBrick:
				switch (blockType2)
				{
				case BlockType.HalfTopBrick:
					return BlockType.Brick;
				case BlockType.HalfTopGrayBrick:
					return BlockType.MixedBrickAndGrayBrick;
				}
				break;
			case BlockType.HalfBottomGrayBrick:
				switch (blockType2)
				{
				case BlockType.HalfTopGrayBrick:
					return BlockType.GrayBrick;
				case BlockType.HalfTopBrick:
					return BlockType.MixedGrayBrickAndBrick;
				}
				break;
			}
			return halfType2;
		}
	}
}
